


const { ccclass, property } = cc._decorator;

@ccclass
export default class TestScene extends cc.Component {
    @property(cc.Node)
    root: cc.Node = null;

    _array: Map<cc.Animation, cc.AnimationClip[]>;

    start() {
        let array = this.root.children;
        this._array = new Map<cc.Animation, cc.AnimationClip[]>();
        array.forEach(arr => {
            let anim = arr.getComponent(cc.Animation);
            this._array.set(anim, anim.getClips());
        });

        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.keyDown, this);
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.keyUp, this);
    }

    keyDown(event: cc.Event.EventKeyboard) {
        switch (event.keyCode) {
            // @ts-ignore
            case cc.macro.KEY.d:
                this._array.forEach((v, k) => {
                    k.play(v[0].name);
                });
                break;
            // @ts-ignore
            case cc.macro.KEY.a:
                this._array.forEach((v, k) => {
                    k.play(v[1].name);
                });
                break;
            // @ts-ignore
            case cc.macro.KEY.space:
                this._array.forEach((v, k) => {
                    k.play(v[2].name);
                });
                break;
            // @ts-ignore
            case cc.macro.KEY.z:
                break;
            // @ts-ignore
            case cc.macro.KEY.x:
                break;
        }
    }

    keyUp(event: cc.Event.EventKeyboard) {
        switch (event.keyCode) {
            // @ts-ignore
            case cc.macro.KEY.d:
                break;
            // @ts-ignore
            case cc.macro.KEY.a:
                break;
            // @ts-ignore
            case cc.macro.KEY.s:
                break;
        }
    }
}